<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryDataForm" v-show="showSearch" :inline="true" label-width="68px">
            <el-form-item label="创建时间" style="width: 308px">
                <el-date-picker
                        v-model="queryDateRange"
                        value-format="YYYY-MM-DD"
                        type="daterange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                ></el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQueryData">搜索</el-button>
                <el-button icon="Refresh" @click="resetQueryData">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button
                    type="primary"
                    plain
                    icon="Plus"
                    @click="handleAddData"
                >导入</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button
                    type="danger"
                    plain
                    icon="Delete"
                    :disabled="multiple"
                    @click="handleDeleteMetAnalogDatas"
                >删除</el-button>
            </el-col>
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getDataList" :columns="showColumns"></right-toolbar>
        </el-row>

        <!-- 表格数据 -->
        <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="id" align="center" key="cnId" prop="cnId" v-if="showColumns[0].visible" />
            <el-table-column label="采集编号" align="center" key="collectId" prop="collectId" v-if="showColumns[1].visible" :show-overflow-tooltip="true" />
            <el-table-column label="目标编号" align="center" key="targetId" prop="targetId" v-if="showColumns[2].visible" :show-overflow-tooltip="true" />
            <el-table-column label="采集时间" align="center" key="collectTime" prop="collectTime" v-if="showColumns[3].visible" :show-overflow-tooltip="true" >
                <template #default="scope">
                    <span>{{ parseTime(scope.row.collectTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="射频频率" align="center" key="rfFreq" prop="rfFreq" v-if="showColumns[4].visible"/>
            <el-table-column label="采样速率" align="center" key="sampleRate" prop="sampleRate" v-if="showColumns[5].visible"/>
            <el-table-column label="记录格式" align="center" key="collectFormat" prop="collectFormat" v-if="showColumns[6].visible">
                <template #default="scope">
                    <dict-tag :options="sys_data_format_type" :value="scope.row.collectFormat" />
                </template>
            </el-table-column>
            <el-table-column label="正反谱" align="center" key="spectrum" prop="spectrum" v-if="showColumns[7].visible">
                <template #default="scope">
                    <dict-tag :options="sys_data_spectrum_type" :value="scope.row.spectrum" />
                </template>
            </el-table-column>
            <el-table-column label="入库人" align="center" key="createBy" prop="createBy" v-if="showColumns[8].visible"/>
            <el-table-column label="入库时间" align="center" key="createTime" prop="createTime" v-if="showColumns[9].visible" :show-overflow-tooltip="true"/>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template #default="scope">
                    <el-tooltip content="删除" placement="top" >
                        <el-button link type="primary" icon="Delete" @click="handleDeleteMetAnalogData(scope.row)" v-hasPermi="['system:role:remove']"></el-button>
                    </el-tooltip>
                </template>
            </el-table-column>
        </el-table>

        <pagination
                v-show="dataList.length > 0"
                :total="dataListTotal"
                v-model:page="queryParams.pageNum"
                v-model:limit="queryParams.pageSize"
                @pagination="getDataList"
        />
    </div>
  <!-- 添加数据对话框 -->
    <el-dialog :title="addDataDialog.title" v-model="addDataDialog.open" append-to-body>
        <el-row :gutter="10">
            <el-form ref="roleRef" :model="addDataDialog.metAnalogData" :inline="true" label-width="100px">
                <el-form-item label="采集编号" prop="collectId">
                    <el-input v-model="addDataDialog.metAnalogData.collectId" />
                </el-form-item>
                <el-form-item label="目标编号" prop="targetId">
                    <el-input v-model="addDataDialog.metAnalogData.targetId" />
                </el-form-item>
                <el-form-item label="采集时间" prop="collectTime">
                    <el-date-picker
                        v-model="addDataDialog.metAnalogData.collectTime"
                        value-format="YYYY-MM-DD hh:mm:ss"
                        type="datetime"
                    />
                </el-form-item>
                <el-form-item label="射频频率" prop="rfFreq">
                    <el-input type="number"  v-model="addDataDialog.metAnalogData.rfFreq" />
                </el-form-item>
                <el-form-item label="采样率" prop="sampleRate">
                    <el-input type="number" v-model="addDataDialog.metAnalogData.sampleRate" />
                </el-form-item>
                <el-form-item label="记录格式" prop="collectFormat">
                        <el-select
                            v-model="addDataDialog.metAnalogData.collectFormat"
                            placeholder="记录格式"
                            style="width: 200px"
                        >
                            <el-option
                                v-for="dict in sys_data_format_type"
                                :key="dict.label"
                                :label="dict.label"
                                :value="dict.value"
                            />
                        </el-select>
                </el-form-item>
                <el-form-item label="正反谱" prop="spectrum">
                    <el-select
                        v-model="addDataDialog.metAnalogData.spectrum"
                        placeholder="正反谱"
                        style="width: 200px"
                    >
                        <el-option
                            v-for="dict in sys_data_spectrum_type"
                            :key="dict.label"
                            :label="dict.label"
                            :value="dict.value"
                        />
                    </el-select>
                </el-form-item>
            </el-form>
        </el-row>
        <el-row :gutter="10">
            <BigFileUpload ref="fileUpload" :upload-files="addDataDialog.uploadFiles"></BigFileUpload>
        </el-row>
        <template #footer>
            <div class="dialog-footer">
                <el-button type="primary" :disabled="!(addDataDialog.uploadFiles.length > 0 && addDataDialog.uploadFiles[0].status === 4)" @click="submitAddData">提交</el-button>
                <el-button @click="cancelAddData">关闭</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script>


import {addDateRange, parseTime} from "@/utils/ruoyi";
import {addMetAnalogData, delMetAnalogData, getMetAnalogData} from "@/api/signal/metAnalogData";

export default {
    name: "Analogcollect",
    data(){
        return{
            dataList:[],
            ids:[],
            multiple:true,//选中列表
            showColumns: [
                { key: 0, label: `Id`, visible: true },
                { key: 1, label: `采集编号`, visible: true },
                { key: 2, label: `目标编号`, visible: true },
                { key: 3, label: `采集时间`, visible: true },
                { key: 4, label: `射频频率`, visible: true },
                { key: 5, label: `采样速率`, visible: true },
                { key: 6, label: `记录格式`, visible: true },
                { key: 7, label: `正反谱`, visible: true },
                { key: 8, label: `入库人`, visible: true },
                { key: 9, label: `入库时间`, visible: true }
            ],
            dataListTotal:0,
            showSearch:true,
            queryDateRange:null,
            queryParams:{
                pageNum: 1,
                pageSize: 10
            },
            loading:false,
            addDataDialog:{
                title:'导入数据',
                open:false,
                uploadFiles:[],
                metAnalogData:{
                    collectId:'',
                    targetId:'',
                    deviceId:'',
                    collectTime:'',
                    rfFreq:0,
                    sampleRate:100,
                    collectFormat:'1',
                    spectrum:'1',
                    dataFile:'',
                },
            },
            sys_data_format_type: [],
            sys_data_spectrum_type:[],
        }
    },
    computed: {},
    watch: {},
    created() {
        let { sys_data_format_type, sys_data_spectrum_type} = this.useDict("sys_data_format_type","sys_data_spectrum_type");
        this.sys_data_format_type = sys_data_format_type
        this.sys_data_spectrum_type = sys_data_spectrum_type
    },
    mounted() {
        this.handleQueryData()
    },
    methods: {
        parseTime,
        getDataList(){
            this.loading = true
            getMetAnalogData(addDateRange(this.queryParams, this.queryDateRange)).then(response => {
                this.dataList = response.rows
                this.dataListTotal = response.total
                this.loading = false
            })
        },
        handleQueryData() { //重新搜搜
            this.queryParams.pageNum = 1
            this.getDataList()
        },
        handleSelectionChange(selection){ //列表复选框勾选
            this.ids = selection.map(item => item.cnId);
            this.multiple = !selection.length
        },
        handleDeleteMetAnalogDatas(){ //删除数据
            const that = this
            this.$modal.confirm('是否确认删除编号为"' + this.ids + '"的数据项？').then(function () {
                delMetAnalogData(that.ids).then(response => {
                    that.$modal.msgSuccess(response.msg)
                    that.getAccessList()
                })
            })
        },
        handleDeleteMetAnalogData(row){
            const that = this
            let idList = []
            idList.push(row.cnId);
            this.$modal.confirm('是否确认删除编号为"' + idList + '"的数据项？').then(function () {
                delMetAnalogData(idList).then(response => {
                    that.$modal.msgSuccess(response.msg)
                    that.getAccessList()
                })
            })
        },
        resetQueryData() { //重置搜索参数
            this.queryDateRange = []
            this.$refs['queryDataForm'].resetFields()
            this.handleQueryData()
        },
        handleAddData(){
            this.addDataDialog.open = true
        },
        submitAddData(){
            this.addDataDialog.loading = true
            this.addDataDialog.metAnalogData.dataFile = this.addDataDialog.uploadFiles[0].filePath;
            alert(JSON.stringify(this.addDataDialog.uploadFiles))
            addMetAnalogData(this.addDataDialog.metAnalogData).then(response => {
                this.$modal.msgSuccess(response.msg);
                this.addDataDialog.loading = false
                this.handleQueryData()
            })
            this.addDataDialog.open = false
        },
        cancelAddData(){
            this.addDataDialog.open = false
        }
    }
}
</script>

<style scoped>

</style>